class connectionObject

	'Credentials
	public 	username,password
	
	'Objects
	public  xmlhttp, cookies, browserEngineHeader
	public 	fileO
	
	public default function init(browserEngine)
		set init = me
		set browserEngineHeader=(new headerObject)(browserEngine)	
		set cookies=(new cookiesObject)()
	end function

	private sub class_Initialize()
		set xmlhttp=CreateObject("WinHttp.WinHttpRequest.5.1")
		set fileO = CreateObject("Scripting.FileSystemObject")
		xmlhttp.Option(4)=13056 ' intSslErrorIgnoreFlags
		xmlhttp.Option(6)=true ' blnEnableRedirects
		xmlhttp.Option(12)=true ' blnEnableHttpsToHttpRedirects
		xmlhttp.setTimeouts 59000,59000,59000,59000
	end sub
	
	public sub credentials(username,password)
		me.username=username
		me.password=password
	end sub

	function getPage(url,method,postData)
		xmlhttp.open method,url,false
		if username<>"" then xmlhttp.SetCredentials username, password, 0
		if method="POST" then xmlhttp.setRequestHeader "Content-type","application/x-www-form-urlencoded"
		browserEngineHeader.addToHeader(xmlhttp)
		cookies.addToHeader(xmlhttp)
		xmlhttp.send postData
		cookies.updateCookies(xmlhttp.getAllResponseHeaders)
		getPage=xmlhttp.responseText
	end function

	function getSOAPPage(url,method,SOAPAction,postData)
		xmlhttp.open method,url,false
		if username<>"" then xmlhttp.SetCredentials username, password, 0
		xmlhttp.setRequestHeader "Content-Type","text/xml; charset=utf-8; action=""" & SOAPAction & """"   'http://tempuri.org/GetFilterXml
		xmlhttp.setRequestHeader "SOAPAction","""" & SOAPAction & """"
		browserEngineHeader.addToHeader(xmlhttp)
		cookies.addToHeader(xmlhttp)
		xmlhttp.send postData
		cookies.updateCookies(xmlhttp.getAllResponseHeaders)
		getSOAPPage=xmlhttp.responseText
	end function
	
	public sub writeFile(f,d)
		set handle = fileO.OpenTextFile(f, 2, True)
		handle.WriteLine(d)
		handle.close
	end sub

end class





